﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using micsun.Logic;
using micsun.SqlDom;
using micsun.Data;
using System.Data.Common;

namespace commfuncs.MAP
{
    
    public class ContentBL
    {
        public IDataReader GetAllContents()
        {
            string sql = "select t.SiteName,m.Id,m.SiteID,m.Portion from t_site_tree t,map_content m where t.SiteID=m.SiteID";
            //"select c.Id,c.SsrKey,c.Portion,s.StateName from map_content c,sp_ssrstate s where s.StateID=c.SsrState";
            return micsunDB.CreateDataAccessor().ExecuteReader(sql, null);
           
        }

        public int getSiteStateBySiteID(string SiteID)
        {
            string sql = "select max(SsrState) from t_sensors where cbt='" + SiteID + "'";
            object i = micsunDB.CreateDataAccessor().ExecuteScalar(sql, null);
            if (i != System.DBNull.Value)
            {
                return Convert.ToInt32(i);
            }
            else
            {
                return 0;
            }
        }

        public string getSiteImage(int State)
        {
            string sql = "select imageName from map_statetoimage where Id=" + State;
            return micsunDB.CreateDataAccessor().ExecuteScalar(sql, null).ToString();
        }

    }
}
